<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../css/style.css" />
		<script type="text/javascript" src="../js/jquery-1.8.0.min.js" ></script>
		<script type="text/javascript" src="../js/head_public.js" ></script>
		<style>
			.baocun{color: #fff;border: 1px solid #fff;background: #ff7e00;position: absolute;z-index: 10;top: 0.12rem;right: 0.2rem;}
		    .xinbie{width: 95%;margin: auto;overflow: hidden;color: #666;}
		    .radio-div img{display: inline-block;width: 0.4rem;}
            .radio-div{padding: 0.3rem 0px;}
            .imgbtn{display: block;float: left;width: 30%;margin-right: 2.4%;}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav ding-bar">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		    <h1 class="mui-title">保养签到</h1>
		</header>
		<div class="mui-content" >
		    <form class="changep-form" >
		    	<div style="background: #fff;">
		    		<p style="border: none;">
			    		<select style="padding: 0px;" id="select">
			    			<option>请选择维保类型</option>
			    		</select>
			    	</p>
		    	</div>
		    	
		    	<div class="kong" ></div>
		    	<div style="background: #fff;">
		    		<p style="border: none;background: #fff;">
			    		<span style="width: 100%;padding-top: 3px;font-size: 0.35rem;">电梯情况</span>
			    		<textarea placeholder="请输入此次维保时电梯情况" style="display: block;border: none;padding: 0px;font-size: 0.35rem;" id="content"></textarea>
			    	</p>
		    	</div>
			    <div class="kong" ></div>
			    <div style="border: none;background: #fff;padding-bottom: 5px;">
		    		<span style="width: 100%;padding-left: 10px;font-size: 0.35rem;line-height: 30px;">上传图片</span>
		    		<div style="width: 100%;height: 75px;margin-top:10px ;">
		    			<!--<input type="file"  style="position: absolute;top: 0px;left: 0px;width: 100%;height: 100%;opacity: 0;"/>-->
		    			<img src="../images/chuantu.png" height="70" class="imgbtn" num="1" style="margin-left: 2%;"/>
		    			<img src="../images/chuantu.png" height="70" class="imgbtn" num="2"/>
		    			<img src="../images/chuantu.png" height="70" class="imgbtn" num="3"/>
		    			<input type="hidden" class="imginput" />
		    			<input type="hidden" class="imginput" />
		    			<input type="hidden" class="imginput" />
		    		</div>
		    	</div>
		    	<div style="background: #efeff4;padding: 2px 0px;">
		        	 <button class="ch-ph-btn" type="button" style="font-weight: bold;letter-spacing: 2px;">提交</button>
		        </div>
		        <div id="tupain"></div>
		    </form>
		</div>
		
		<script src="../js/mui.min.js"></script>
		<script src="../js/session.js"></script>
		<script src="../js/common.js"></script>
		<script>
		     var work_id=getCookie("workid");
             var work=getCookie("work");
             var userid=getCookie("userid");
             var id=getQueryString("id");
             var num="";
             if(userid==""||userid==null){
             	alert("您还没有登录，请先登录")
             	location.href="../public/login.html";
             }else{
             	if(work!="2"){
					alert("您不是维修人员,您没有权限")
					mui.openWindow({url:"../public/index.html"})
				}
             	var param={};
             	param.id=id;
             	param.member_id=userid;            
             	$.post(net+"/public/index.php?s=api/elevator/add_service/",param,function(res){
             		if(res.code=="200"){
             			if(res.result.type!=null&&res.result.type.length!=0){
             				var str="";
             				$.each(res.result.type,function(index,val){
             					str+='<option value="'+this.id+'">'+this.name+'</option>'
             				})
             				$("#select").append(str)
             			}
             		}
             		
             	})
             }
		
//			图片上传
            
			 //扩展API完成后执行的操作
                function plusReady(){               
                 //给选中的li增加判别class
                     mui(".mui-content").on("tap",".imgbtn",function(){
                     	num=$(this).attr("num")
                     	page.imgUp();
                     })  
                } 
                //弹出系统按钮选择框
                var page=null; 
                page={ 
                    imgUp:function(){ 
                        var m=this; 
                       /* console.log(m);*/
                        plus.nativeUI.actionSheet({cancel:"取消",buttons:[ 
                            {title:"拍照"}, 
                            {title:"从相册中选择"} 
                        ]}, function(e){//1 是拍照  2 从相册中选择 
                            switch(e.index){ 
                                case 1:appendByCamera();break; 
                                case 2:appendByGallery();break; 
                            } 
                        }); 
                    } 
                } 
               
            // 拍照添加文件
            function appendByCamera(){
                plus.camera.getCamera().captureImage(function(e){
                    console.log("e is" +  e);
                    plus.io.resolveLocalFileSystemURL(e, function(entry) {
                        var path = entry.toLocalURL();
                        upload(path)
                    }, function(e) {
                        mui.toast("读取拍照文件错误：" + e.message);
                    });      
                });   
            }
            // 从相册添加文件
            function appendByGallery(){
                plus.gallery.pick(function(path){
                    upload(path)
                  
                });
            }   
            //服务端接口路径
            var server = net+"/public/index.php?s=api/elevator/service_img_uplode";
            //获取图片元素
            var files = document.getElementById('avatar');
            // 上传文件
            function upload(path){
                var wt=plus.nativeUI.showWaiting();
                var task=plus.uploader.createUpload(server,
                    {method:"POST",
                     member_id:userid
                    },
                    function(t,status){ //上传完成
//                  	alert(JSON.stringify(t))
                        if(status==200){
                            var data=$.parseJSON(t.responseText);
                            $(".imgbtn:nth-of-type("+num+")")[0].src=net+data.result+'?timestep='+Math.random();
                            $(".imginput:nth-of-type("+num+")").val(data.result);
                            alert("上传成功");
                            wt.close(); //关闭等待提示按钮 
                        }else{
                            alert("上传失败："+status);
                            wt.close();//关闭等待提示按钮
                        }
                    }
                );  
                //添加其他参数
                task.addData("member_id",userid);
                task.addData("id",id);
                task.addData("num",num);
                task.addData("type","1");
                task.addFile(path,{key:"serviceimg"});
                task.start();
            } 
            //扩展API是否准备好，如果没有准备好则监听plusReady 
            if(window.plus){
                plusReady();
            }else{
                document.addEventListener("plusready",plusReady,false);
            }
            
           mui("form").on("tap",".ch-ph-btn",function(){
           	   var eventid=$("#select").val();
           	   var content=$("#content").val();
           	   var imgs="";
           	   $(".imginput").each(function(i){
           	   	  if($(this).val()!=""&&$(this).val()!=null){
           	   	  	 imgs+=$(this).val()+","
           	   	  }
           	   })
           	  if(eventid==""||eventid==null){
           	  	alert("请选择保养类型")
           	  	return false;
           	  }else if(content==""||content==null){
           	  	alert("请填写电梯情况")
           	  	return false;
           	  }else if(imgs==null||imgs.length==0){
           	  	alert("请上传图片")
           	  	return false;
           	  }
           	  var params={}
           	  params.member_id=userid;
           	  params.id=id;
           	  params.imgs=imgs;
           	  params.eventid=eventid;
           	  params.content=content;
           	   $.post(net+"/public/index.php?s=api/elevator/add_service_action/",params,function(res){
           	   	 if(res.code=="200"){
           	   	 	alert("提交成功")
           	   	 	location.href="baoyangrili.html"
           	   	 } 
           	   })
           })
		</script>
	</body>

</html>